package net.yeah.mickey_zhouyou.database.util;

import net.yeah.mickey_zhouyou.database.util.string_policy.IStringToObjectPolicy;
import net.yeah.mickey_zhouyou.database.util.string_policy.IObjectToStringPolicy;

public class StringUtil {

	static boolean isSampleType(Class<?> clazz) {
		return ObjectStringConvertPolicyUtil.getToStringPolicy(clazz.getName()) != null;
	}

	public static <T> String sampleTypeObjToString(T data) {
		if (data == null)
			return "";

		IObjectToStringPolicy policy = ObjectStringConvertPolicyUtil
				.getToStringPolicy(data.getClass().getName());
		return policy.convert(data);
	}

	public static <T> T strToSampleTypeObj(String str, String className) {
		@SuppressWarnings("unchecked")
		IStringToObjectPolicy<T> policy = (IStringToObjectPolicy<T>) ObjectStringConvertPolicyUtil
				.getToObjectPolicy(className);
		return policy.convert(str);
	}

	public static boolean isEmpty(String str) {
		return (str == null || str.trim().length() == 0);
	}

}
